<template>
	<div id="workshop">
		<div class="entries">
			<el-tree 
				:data="definedEntries" 
				highlight-current
				@node-click="treeNodeClickHandle"
			/>
		</div>
		
		<div class="details" v-show="asyncDetailView">
			<transition name="details" mode="out-in">
				<component :is="asyncDetailView"></component>
			</transition>
		</div>
	</div>
</template>

<script>
	
	import { defineComponent } from "vue";
	
	export default defineComponent({
		name: 'WorkshopView'
	})
	
</script>

<script setup>
	
	import { defineAsyncComponent, ref, shallowRef, computed, reactive, nextTick } from "vue";
	import definedEntries from "@/constant/workshopEntries";
	
	const detailArgs = ref([]);
	
	const asyncDetailView = shallowRef();
	
	function treeNodeClickHandle(data) {
		if (!data.isLeaf) return;
		detailArgs.value = data.id.split('-');
		asyncDetailView.value = defineAsyncComponent(() => import(`./details/${detailArgs.value.join('/')}`));
	}
	
</script>

<style lang="scss" scoped>
	
	@import '@/theme/define/index.scss';
	@import '@/theme/material/media.scss';
	
	#workshop {
		@include viewLayout;
		display: grid;
		gap: 10px;
		grid-template-columns: 100%;
		grid-auto-rows: auto;
		padding-top: 20px;
		padding-bottom: 20px;
		@include mediaSm {
			grid-template-columns: 220px 1fr;
			align-items: stretch;
			padding-top: 40px;
			padding-bottom: 40px;
			overflow: auto;
			height: calc(100% - 64px);
		}
	}
	
	.entries {
		overflow: auto;
		:deep(.el-tree) {
			background: transparent;
		}
	}
	
	.details {
		overflow: hidden auto;
		padding: 20px 32px;
		background: #fff;
		box-shadow: 0 0 10px #d8d8d8;
		border-radius: 10px;
	}
	
	.details-enter-from {
		transform: translateX(-10px);
		opacity: 0;
	}
	.details-leave-to {
		transform: translateX(10px);
		opacity: 0;
	}
	
	.details-enter-active,
	.details-leave-active {
		transition: all .25s;
	}
	
</style>